package com.zzx.boot.websocket.session;

import io.netty.channel.Channel;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;


public class WebSocketSession {
    public static final Map<String, Channel> sessionMap = new HashMap();

    // 添加
    public static void addSession(String userId,Channel channel) {
        sessionMap.put(userId, channel);
    }
    // 删除
    public static Channel removeSessionById(String userId) {

        return sessionMap.remove(userId);
    }
    // 通过channel删除
    public static boolean removeSessionByChannel(Channel channel) {
        return sessionMap.values().remove(channel);
    }

    // 是否存在 return session
    public static Boolean hasSession(String userId) {
        return sessionMap.containsKey(userId);
    }
    // 根据id获取
    public static Channel getSession(String userId) {
        return sessionMap.get(userId);
    }
    // 连接人数
    public static Integer countSession() {
        return sessionMap.size();
    }


}
